package com.aat.dxfy.nocfg.conf;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.util.ClassUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import com.aat.dxfy.nocfg.filter.TestFilter;

public class ServletInitializer extends AbstractDispatcherServletInitializer {

	@Override
	protected WebApplicationContext createServletApplicationContext() {
		AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
		context.scan(ClassUtils.getPackageName(getClass()));
		return context;
	}

	@Override
	protected String[] getServletMappings() {
		return new String[]{"*.do"};
	}

	@Override
	protected WebApplicationContext createRootApplicationContext() {
		
		return null;
	}

	@Override
	public void onStartup(ServletContext servletContext)
			throws ServletException {
		servletContext.addFilter("test", new TestFilter()).addMappingForUrlPatterns(null, false, "/*");;
		super.onStartup(servletContext);
	}
	
}
